import { Controller, Post, UploadedFile, UploadedFiles, UseInterceptors } from '@nestjs/common';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import { FileUploadService } from './file-upload.service';

@Controller('file-upload')
export class FileUploadController {
  constructor(private readonly fileUploadService: FileUploadService) {}

  /**
   * 上传单个图片
   * @param file - 上传的图片文件
   * @returns 包含图片访问路径的响应
   */
  @Post('single')
  @UseInterceptors(FileInterceptor('file'))
  async uploadSingleFile(@UploadedFile() file: Express.Multer.File) {
    const result = await this.fileUploadService.uploadFile(file);
    return {
      code: 200,
      message: '上传成功',
      data: result
    };
  }

  /**
   * 上传多个图片
   * @param files - 上传的图片文件数组
   * @returns 包含所有图片访问路径的响应
   */
  @Post('multiple')
  @UseInterceptors(FilesInterceptor('files'))
  async uploadMultipleFiles(@UploadedFiles() files: Express.Multer.File[]) {
    const results = await this.fileUploadService.uploadMultipleFiles(files);
    return {
      code: 200,
      message: '上传成功',
      data: results
    };
  }
}